import React from 'react'
import { Switch,Route,Redirect } from 'react-router-dom'
import './App.less'
import {SpinLoading} from 'antd-mobile'
// import Login from './pages/login/Login'
// import Register from './pages/register/Register'
// import Index from './pages/index/Index'
// import Detail from './pages/detail/Detail'
// import Search from './pages/search/Search'
// import List from './pages/list/List'
let Index = React.lazy(() => import("./pages/index/Index"));
let Search = React.lazy(() => import("./pages/search/Search"));
let Login = React.lazy(() => import("./pages/login/Login"));
let Register = React.lazy(() => import("./pages/register/Register"));
let Detail = React.lazy(() => import("./pages/detail/Detail"));
let List = React.lazy(() => import("./pages/list/List"));
let Coupon = React.lazy(() => import("./pages/Coupon/Coupon"));



export default function App() {
  return (
    <div className='App'>
      <React.Suspense fallback={<SpinLoading style={{ '--size': '48px', position:'absolute',top:'50%',left:'50%',transform:'translate(-50%,-50%)' }} />}>
        <Switch>
          {/* 一级路由 */}
          <Route path="/login" component={Login}></Route>
          <Route path="/register" component={Register}></Route>
          {/* <Route path="/index" component={Index}></Route> */}
          {localStorage.getItem("userInfo")?<Route path="/index" component={Index} />:<Redirect to="/login"></Redirect> }
          {/* <Route path="/detail/:id" component={Detail}></Route>
           */}
          {localStorage.getItem("userInfo")?<Route path="/detail/:id" component={Detail} />:<Redirect to="/login"></Redirect> }
          {/* <Route path="/search/:id" component={Search}></Route> */}
          {localStorage.getItem("userInfo")?<Route path="/search/:id" component={Search} />:<Redirect to="/login"></Redirect> }
          {/* <Route path="/list/:id" component={List}></Route> */}
          {localStorage.getItem("userInfo")?<Route path="/list" component={List} />:<Redirect to="/login"></Redirect> }
          {localStorage.getItem("userInfo")?<Route path="/coupon" component={Coupon} />:<Redirect to="/login"></Redirect> }
          <Redirect to="/login"></Redirect>
        </Switch>
      </React.Suspense>
    </div>
  )
}